package cn.wen.javax.ui.template;

import java.io.IOException;

import freemarker.template.Configuration;
import freemarker.template.TemplateException;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;

/**
 * Title：FreeMarker Factory
 * <p>
 * Description：
 * <p>
 * Copyright：Copyright (c) 2010-2012
 * 
 * @author <a href="mailto:ct_wen@qq.com">ctwen</a>, 温承瑭
 * @version Revision：1.0 Date：2011/4/9 Description：初完成。
 *          <p>
 * @see org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean
 * @see org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer
 */
public class FreeMarkerConfigurationFactoryBean implements FactoryBean<Configuration>, InitializingBean {

    private Configuration cfg;

    @Override
    public void afterPropertiesSet() throws IOException, TemplateException {
	if (cfg != null) {
	    return;
	}
	this.cfg = new Configuration();
    }

    public void setConfiguration(Configuration cfg) {
	this.cfg = cfg;
    }

    @Override
    public Configuration getObject() {
	return this.cfg;
    }

    @Override
    public Class<? extends Configuration> getObjectType() {
	return Configuration.class;
    }

    @Override
    public boolean isSingleton() {
	return true;
    }

}
